<template>
  <basic-container :btnFlag = true>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>

      <div class="card-body">
        <avue-crud :data="subjectListData"
                   :option="tableoption"
                   :page="page"
                   :table-loading="tableLoading"
                   @size-change="sizeChange"
                   @current-change="currentChange"
                   @refresh-change="refreshChange"
                   @search-change="searchChange"
                   @search-reset="refreshChange"
                   class="avuecrud">
          <template slot-scope="scope" slot="menu">
            <div class="menu-title" @click.stop="reviewOpinion(scope.row,scope.index)">
              <i class="iconfont iconview icon-primary"></i>
              <p class="menu-title-text">评审意见</p>
            </div>
          </template>
        </avue-crud>
      </div>
      <detail-dialog :achievementId="achievementIdDD"
                     :pmuc="pmucDD"
                     :showDetailDialog.sync="showDetailDialog"
                     :key="achievementIdDD"></detail-dialog>
      <!--评审意见弹出框-->
      <el-dialog title="评审意见" :visible.sync="reviewOpinionDialogVisible" width="70%">
        <el-form
          label-width="130px"
          :model="subjectForm"
          style="padding-right: 30px;"
          :rules="subjectInfosrules"
          ref="subjectForm"
        >
          <el-row>
            <el-col :span="11">
              <el-form-item class="form-item-release" label="专家组长 :" prop="expertLeader">
                <el-input v-model="subjectForm.expertLeader" placeholder="请输入专家组长"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="22">
              <el-form-item class="form-item-release" label="专家组成员名单 :" prop="expertList">
                <el-input
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 4}"
                  placeholder="请输入专家组成员名单"
                  v-model="subjectForm.expertList"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item class="form-item-release" label="评审时间 :" prop="reviewTime" style="float: left;">
                <div>
                  <el-date-picker
                    style="width:320px"
                    v-model="subjectForm.reviewTime"
                    type="datetime"
                    placeholder="选择评审时间"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    :picker-options="expireTimeOption"
                  >
                  </el-date-picker>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="22">
              <el-form-item class="form-item-release" label="评审结论 :" prop="conclusion">
                <el-input
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 4}"
                  placeholder="请输入评审结论"
                  v-model="subjectForm.conclusion"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div class="form-group-file-need">
          <span class="form-label-file"><b style="color:red;margin-right: 5px;">*</b>评审报告 :</span>
          <el-upload
            class="upload-demo"
            ref="uploadrelated"
            action="string"
            :http-request="fileUploadRequest"
            :on-preview="fileHandlePreview"
            :on-remove="fileHandleRemove"
            :file-list="fileTypeIds['附件']"
            :auto-upload="true">
            <el-button slot="trigger" size="small" type="primary">点击上传</el-button>
          </el-upload>
        </div>
        <div class="form-group-file" style="padding-left:43px;">
          <span class="form-label-file">其他附件 :</span>
          <el-upload
            class="upload-demo"
            ref="uploadrelated"
            action="string"
            :http-request="otherfileUploadRequest"
            :on-preview="otherfileHandlePreview"
            :on-remove="otherfileHandleRemove"
            :file-list="fileTypeIds['其他附件']"
            :auto-upload="true">
            <el-button slot="trigger" size="small" type="primary">点击上传</el-button>
          </el-upload>
        </div>
        <div class="form-submit">
          <el-button type="primary" @click.stop="commitList()">保存</el-button>
          <el-button type="info" @click.stop="goBack()">关闭</el-button>
        </div>
      </el-dialog>

    </div>
  </basic-container>
</template>

<script>
  import { resultList} from "@/api/planning/result";
  import {PROJECT_DIC} from '@/const/dict'
  import { makeList } from "@/api/make";
  import {makeExpertRules} from "@/const/infoRules";
  import fileTypeMixin from "@/mixins/fileTypeMixin";
  import {addMakeExpert} from "@/api/make";
  export default {
    name: "argumentReview",
    mixins:[fileTypeMixin],
    created(){
      this.getResultList(this.page)
      window.detailDialog = this.detailDialog;
    },
    data(){
      return{
        headerData:{
          title:'论证评审'
        },
        subjectListData:[],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        tableoption: {
          page: true,
          menuWidth:120,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
  indexWidth:70,
          index: true,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn:false,
          keyId: "id",
          column: [
            {
              label: "规划名称",
              prop: "title",
              cell: true,
              search:true,
              formatter: function (row, value, label, column) {
                return '<a style="cursor: pointer;" onclick="detailDialog(\'' + row.achievementId + '\'' + ',' + '\'' + row.pmuc + '\')">' + value + '</a>';
              },
            },
            {
              label: "年份",
              width: 100,
              prop: "year",
              cell: true
            },
            {
              label: "规划类型",
              width: 100,
              prop: "category",
              type: "select",
              dicData: PROJECT_DIC.CATEGORY,
              cell: true
            },
            {
              label: "申报单位",
              width: 140,
              prop: "orgName",
              cell: true
            }
          ]
        },
        tableLoading:false,
        achievementIdDD: null,
        pmucDD: null,
        showDetailDialog: null,
        reviewOpinionDialogVisible: false,
        subjectInfosrules:makeExpertRules,// 表单验证
        subjectForm: {
          achievementId:null,
          conclusion:null,
          expertLeader:null,
          expertList:null,
          fileIds:[],
          reportFileIds:[],
          reviewTime:null,
        },
        resetSubjectForm: {
          achievementId:null,
          conclusion:null,
          expertLeader:null,
          expertList:null,
          fileIds:[],
          reportFileIds:[],
          reviewTime:null,
        },
        fileType:'附件',
        expireTimeOption: {
          disabledDate(date) { //disabledDate 文档上：设置禁用状态，参数为当前日期，要求返回 Boolean
            return date.getTime() <= Date.now();
          }
        },
        titleLikes: '',


      }
    },
    methods:{
      detailDialog(achievementId, pmuc) {
        this.achievementIdDD = Number(achievementId);
        this.pmucDD = pmuc;
        this.showDetailDialog = true;
      },
      getResultList(page, params){
        this.tableLoading = true;
        makeList(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          states:'2',
        },params)).then(response => {
          this.subjectListData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false
        })
      },
      //搜索回调
      searchChange(params){
        this.page.currentPage = 1
        this.getResultList(this.page,this.dealSearchParam(params))
      },
      refreshChange(){
      this.getResultList(this.page)
      },
      // 处理搜索过滤
      dealSearchParam(params) {
        if (params.title) {
          params.titleLike = params.title
        }else{
          params.titleLike =""
        }
        this.titleLikes=  params.titleLike;
        return params;
      },
      currentChange(currentPage) {
        let page = this.page;
        page.currentPage = currentPage;
        let params={titleLike: this.titleLikes}
        this.getResultList(page, params);
      },
      sizeChange(pageSize) {
        let page = this.page;
        page.pageSize = pageSize;
        let params={titleLike: this.titleLikes}
        this.getResultList(page, params);
      },

      //评审意见
      // reviewOpinion(row,index){
      //   let src = `/reviewOpinion/detail/${row.achievementId}`;
      //   this.$router.push({
      //     path: src,
      //     query: {
      //       name:row.title,
      //       pmuc:row.pmuc
      //     }
      //   })
      // },

      reviewOpinion(row,index){
        //将表单清空
        this.subjectForm = {
          achievementId:null,
          conclusion:null,
          expertLeader:null,
          expertList:null,
          fileIds:[],
          reportFileIds:[],
          reviewTime:null,
        };
        this.fileTypeIds['其他附件'] = [];
        this.fileTypeIds['附件'] = [];
        this.subjectForm.reportFileIds = [].concat();
        this.subjectForm.fileIds = [].concat();


        this.subjectForm.achievementId = row.achievementId;
        this.reviewOpinionDialogVisible = true;
      },
      goBack(){
        this.reviewOpinionDialogVisible=false;
        this.subjectForm = this.resetSubjectForm;
        this.fileTypeIds['其他附件'] = [];
        this.fileTypeIds['附件'] = [];
        this.subjectForm.reportFileIds = [].concat();
        this.subjectForm.fileIds = [].concat();
      },
      commitList(){
        this.subjectForm.reportFileIds = this.getFileIds(this.fileTypeIds[this.fileType]);
        if(this.subjectForm.reportFileIds==null||this.subjectForm.reportFileIds.length==0){
          this.$notify({
            title: "提醒",
            type: "warning",
            message: "请上传评审报告",
            duration: 2000
          });
          return;
        }

        this.$confirm("确定评审意见么?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.$refs.subjectForm.validate(valid => {
            if (valid) {

              this.subjectForm.fileIds = this.getFileIds(this.fileTypeIds['其他附件']);
              addMakeExpert(this.subjectForm).then(response => {
                if (response.data.code == 0) {
                  this.$notify({
                    title: "成功",
                    message: "添加成功",
                    type: "success",
                    duration: 2000
                  });
                  this.reviewOpinionDialogVisible=false;
                }
              })
            }
          })
        })
      },
      otherfileUploadRequest(file){
        this.fileUploadRequestName(file,'其他附件')
      },
      // 材料清单附件预览
      otherfileHandlePreview(file){
        this.fileHandlePreviewName(file,'其他附件')
      },
      // 材料清单附件移除
      otherfileHandleRemove(file){
        this.fileHandleRemoveName(file,'其他附件')
      },



    }
  }
</script>

<style lang="scss" scoped>

</style>
